package taller2.controller.listeners.evaluateMeButtons;

import java.awt.event.ActionEvent;
import java.util.ArrayList;

import taller2.interfaces.AlgorithmApplicator;
import taller2.interfaces.Graph;
import taller2.interfaces.Node;
import taller2.model.factorys.GraphFactory;
import taller2.model.graph.algorithms.CyclesDetectionApplicator;
import taller2.utils.Constants.Colores;
import taller2.view.windows.supervisor.CycleDetectionSupervisorWindow;

public class CycleDetectionEvaluateMeButtonListener extends EvaluateMeButtonListener{

	public CycleDetectionEvaluateMeButtonListener(AlgorithmApplicator aplicator) {
		super(aplicator);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		menu.unselectButtons();
		
		CyclesDetectionApplicator str = (CyclesDetectionApplicator)aplicator;
		
		String path = str.getStartingGraphPath();

		if(path != null){
			Graph g;
		
			boolean directed = str.wasDirected();
			if (directed){
				g = GraphFactory.directedGgraphInstance();
			}else{
				g = GraphFactory.undirectedGraphInstance();
			}
		
			g.load(path);
			g.unselectNodes();
			g.unselectConnections();
		
			ArrayList<Node> nodes = g.getNodes();
			int cantNodes = nodes.size();
		
			if(cantNodes > 0){		
				Node start = nodes.get(0);
				start.changeColor(Colores.green);		
		
				new CycleDetectionSupervisorWindow(g);
			}
		}
	}

}
